package com.haochang.chunkvod.app.config;


import com.haochang.base.VodApplication;
import com.haochang.chunkvod.app.info.InitType;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

/**
 * 
 * @author lxl
 *		2015-1-5-上午11:52:59
 *		
 *		包含应用存储路径,应用版本,及其它应用相关配置
 *
 */
public class AppConifg
{
	private static String appVersionName = "";
	private static String appVersionNameForTest = "";
	private static int appVersionCode = 0;
	private static String appChannel = "";
	public static int appDbVersion = 5;

	private static InitType mInitType = InitType.None;

	/**
	 * 初始化
	 */
	public static void init()
	{
		mInitType = InitType.Normal;
		ApplicationInfo applicationInfo;
		try
		{
			applicationInfo = VodApplication.appContext.getPackageManager().getApplicationInfo(VodApplication.appContext.getPackageName(),
					PackageManager.GET_META_DATA);
			if (applicationInfo != null)
			{
				appChannel = applicationInfo.metaData.getString("Channel");
				appVersionNameForTest = applicationInfo.metaData.getString("testVersionName");
			}
		} catch (NameNotFoundException e)
		{
			e.printStackTrace();
			appChannel = "mc";
			mInitType = InitType.AppConfigError;
		}

		PackageInfo packageInfo;
		try
		{
			packageInfo = VodApplication.appContext.getPackageManager().getPackageInfo(VodApplication.appContext.getPackageName(),
					PackageManager.GET_CONFIGURATIONS);
			appVersionName = packageInfo.versionName;
			appVersionCode = packageInfo.versionCode;
		} catch (NameNotFoundException e)
		{
			e.printStackTrace();
			appVersionName = "4.2.0";
			mInitType = InitType.AppConfigError;
		}
	}

	/**
	 * 获取初始化结果
	 * @return
	 */
	public static InitType getInitType()
	{
		return mInitType;
	}

	/**
	 * 版本名称
	 * @return
	 */
	public static String appVersionName()
	{
		return appVersionName;
	}
	
	/**
	 * 版本名称-测试专用
	 * @return
	 */
	public static String appVersionNameForTest()
	{
		return appVersionNameForTest;
	}

	/**
	 * 版本号
	 * @return
	 */
	public static int appVersionCode()
	{
		return appVersionCode;
	}

	/**
	 * 渠道
	 * @return
	 */
	public static String appChannel()
	{
		return appChannel;
	}
}
